<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>嵌套路由的使用</title>
    <script src="./lib/vue-2.4.0.js"></script>
    <script src="./lib/vue-router-3.0.1.js"></script>
</head>
<body>
    <div id="app">
        <ul>
            <li>
                <router-link to="/index">首页</router-link>
            </li>
            <li>
                <router-link to="/about">关于我们</router-link>
            </li>
        </ul>
        <!-- 占位符:路径切换后对应的视图页面会在这个区域展示 -->
        <router-view></router-view>
    </div>

    <template id="index">
        <div>
            <h1>{{title}}</h1>
            <!-- 路由占位符 -->
            <router-view></router-view>
        </div>
    </template>
</body>
<script>
    var index=Vue.component('index',{
        template:`#index`,
        data:function(){
            return {
                title:'首页'
            }
        },
        components:{
            banner:{
                template:'<div><h1>{{title}}</h1></div>',
                data:function(){
                    return {
                        title:'轮播图'
                    }
                }
            }
        }
    });
    var about=Vue.component('about',{
        template:`<div><h1>{{title}}</h1></div>`,
        data:function(){
            return {
                title:'关于我们'
            }
        }
    });
    var router=new VueRouter({
        routes:[
            {
                name:'index',
                path:'/index',
                component:index,
                // children:[
                //     {
                //         name:'banner',
                //         path:'/banner',
                //         component:banner
                //     }
                // ]
            },
            {
                name:'about',
                path:'/about',
                component:about
            }
        ]
    });
    var vm=new Vue({
        el:'#app',
        data:{
        },
        methods:{
        },
        // 挂载路由配置对象
        router:router
    });
</script>
</html>